﻿using iMES.Cese.IRepositories;
using iMES.Cese.IServices;
using iMES.Core.Utilities;
using iMES.Entity.DomainModels;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace iMES.Cese.Services
{
    public partial class Ce_CeseService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly ICe_Cese _CeseRepository;//访问数据库

        public Ce_CeseService(IHttpContextAccessor httpContextAccessor, ICe_Cese ceseRepository): base(ceseRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _CeseRepository = ceseRepository;
        }
        WebResponseContent _webResponse = new WebResponseContent();
        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override WebResponseContent Add(SaveModel saveDataModel)
        {
            //此处saveModel是从前台提交的原生数据，可对数据进修改过滤
            AddOnExecuting = (cese ho, object list) =>
            {
                //如果返回false,后面代码不会再执行
                if (repository.Exists(x => x.name == ho.name))
                {
                    return _webResponse.Error("名称重复");
                }
                return _webResponse.OK();
            };
            return base.Add(saveDataModel);
        }
    }
}
